using System;
using System.Reflection;
using System.Collections.Generic;
using System.Text;

using AIFSContentManagementSystem.ArticleManagement;
using AIFSContentManagementSystem.ArticleManagement.Messages;

using AIFSContentManagementSystem.CriteriaManagement;
using AIFSContentManagementSystem.CriteriaManagement.Messages;

namespace AIFSContentManagementSystem
{
    public class AIFSCMSFacade
    {
        public AIFSCMSResponse Process(CriteriaRequest request)
        {
            IManagerContext managerContext = ManagerContextRepository.GetManagerContext(false);

            ICriteriaManager manager = managerContext.GetCriteriaManager();

            MethodInfo methodProcess = manager.GetType().GetMethod("Process", new Type[] { request.GetType() });

            AIFSCMSResponse result = (AIFSCMSResponse)methodProcess.Invoke(manager, new object[] { request });

            return result;
        }

        public AIFSCMSResponse ProcessInTransaction(CriteriaRequest request)
        {
            IManagerContext managerContext = ManagerContextRepository.GetManagerContext(true);

            ICriteriaManager manager = managerContext.GetCriteriaManager();

            MethodInfo methodProcess = manager.GetType().GetMethod("Process", new Type[] { request.GetType() });

            AIFSCMSResponse result = (AIFSCMSResponse)methodProcess.Invoke(manager, new object[] { request });

            return result;
        }

        public AIFSCMSResponse Process(ArticleRequest request)
        {
            IManagerContext managerContext = ManagerContextRepository.GetManagerContext(false);

            IArticleManager manager = managerContext.GetArticleManager();

            MethodInfo methodProcess = manager.GetType().GetMethod("Process", new Type[] { request.GetType() });

            AIFSCMSResponse result = (AIFSCMSResponse)methodProcess.Invoke(manager, new object[] { request });

            return result;
        }

        public AIFSCMSResponse ProcessInTransaction(ArticleRequest request)
        {
            IManagerContext managerContext = ManagerContextRepository.GetManagerContext(true);

            IArticleManager manager = managerContext.GetArticleManager();

            MethodInfo methodProcess = manager.GetType().GetMethod("Process", new Type[] { request.GetType() });

            AIFSCMSResponse result = (AIFSCMSResponse)methodProcess.Invoke(manager, new object[] { request });

            return result;
        }
    }
}
